Рассмотрим этот фрагмент кода, который пытается получить цвет темы из локального хранилища устройства iOS:
var color = UserDefaults.standard.string(forKey: "themeColor")! print(color)
Ответ: Первая строка извлекает цвет темы из user defaults. Этот метод, однако, возвращает optional (поскольку themeColor может быть не определен). Если ключ не найден, возвращается nil, что приводит к крашу:
fatal error: unexpectedly found nil while unwrapping an Optional value
Это происходит потому, что в первой строке используется ! для force unwrap optional, которое теперь nil. Force unwrapping должно использоваться только тогда, когда вы на 100% уверены, что значение не nil.
Чтобы исправить это, вы можете использовать optional binding для проверки, найдено ли значение для ключа:
if let color = defaults.stringForKey("themeColor") { print(color)}
Рассмотрим этот фрагмент кода, который пытается получить цвет темы из локального хранилища устройства iOS:
var color = UserDefaults.standard.string(forKey: "themeColor")! print(color)
Ответ: Первая строка извлекает цвет темы из user defaults. Этот метод, однако, возвращает optional (поскольку themeColor может быть не определен). Если ключ не найден, возвращается nil, что приводит к крашу:
fatal error: unexpectedly found nil while unwrapping an Optional value
Это происходит потому, что в первой строке используется ! для force unwrap optional, которое теперь nil. Force unwrapping должно использоваться только тогда, когда вы на 100% уверены, что значение не nil.
Чтобы исправить это, вы можете использовать optional binding для проверки, найдено ли значение для ключа:
if let color = defaults.stringForKey("themeColor") { print(color)}
With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.
Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.Библиотека мобильного разработчика | Android iOS Swift Retrofit Moshi Chuck from kr